﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Cadcam7Moddel.Context;
using Cadcam7Moddel.Model;
using camcad7Home.CultureHelper;
namespace camcad7Home.Controllers
{
    public class HomeController : CultureController
    {
        DataContext db = new DataContext();   
        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

            return View("NewIndex");
        }

        public ActionResult Language()
        {
            var langs = db.NgonNgus.OrderByDescending(m=>m.Ma);
            return PartialView(langs);
        }
        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
        public ActionResult leftmenu()
        {
            string a = Request.Cookies["_culture"]["lang"];
            List<Listloaitin> lls = new List<Listloaitin>();
            var ltin= (from t in db.Loaitin
                      where t.Hienphai==false && t.LangID==a
                      select t).ToList();
            foreach (var n in ltin)
            {
                Listloaitin ls = new Listloaitin();
                ls.id = n.ID;
                ls.ten = n.Ten;
                var s = (from k in db.Tintuc
                         where k.LoaitinID == n.ID && k.Hien == true &&k.LangID == a
                         select k).ToList();
                ls.tin = s;
                lls.Add(ls);
            }
            
            return PartialView(lls);
        }
        public ActionResult rightmenu()
        {
            string a = Request.Cookies["_culture"]["lang"];
            List<Listloaitin> lls = new List<Listloaitin>();
            var ltin = (from t in db.Loaitin
                        where t.Hienphai == true && t.LangID == a
                        select t).ToList();
            foreach (var n in ltin)
            {
                Listloaitin ls = new Listloaitin();
                ls.id = n.ID;
                ls.ten = n.Ten;
                var s = (from k in db.Tintuc
                         where k.LoaitinID == n.ID && k.Hien == true && k.LangID == a
                         select k).ToList();
                ls.tin = s;
                lls.Add(ls);
            }

            return PartialView(lls);
        }
        public ActionResult menuchinh()
        {
            var langstr = Request.Cookies["_culture"]["lang"];
            var menu = db.Trang.Where(m => m.LangID == langstr);
            return PartialView(menu);
        }
        public ActionResult slideshow()
        {
           
            var s = (from n in db.Slideshow
                    
                     orderby n.ID descending
                     select n).ToList();
            return PartialView(s);
        }
        public ActionResult thongtin()
        {
            string a = Request.Cookies["_culture"]["lang"];
            var t = (from n in db.Cauhinhtrang
                     where n.LangID==a
                     orderby n.ID descending
                     select n).Take(1).FirstOrDefault();
            return PartialView(t);
        }
        public ActionResult logo()
        {
            var t = (from n in db.Cauhinhtrang
                     orderby n.ID descending
                     select n).Take(1).FirstOrDefault();
            return PartialView(t);
        }
        public ActionResult mainchinh()
        {
            string a =Request.Cookies["_culture"]["lang"];
            var m = (from n in db.Trang
                     where n.Hien == true &&n.Trangchu==true&&n.LangID==a

                     orderby n.Thutu ascending
                     select n).FirstOrDefault() ;
            return PartialView(m);
        }
        public ActionResult supportlist()
        {
            var sups = db.Supports.FirstOrDefault();
            return PartialView(sups);
        }
        public ActionResult ListMons()
        {
            string a = Request.Cookies["_culture"]["lang"];
            var subs = db.Subjects.Where(m => m.LangID == a).ToList();
            List<SubjectLS> listls = new List<SubjectLS>();
            foreach (var sls in subs)
            {
                SubjectLS s = new SubjectLS();
                s.ID = sls.ID;
                s.Name = sls.Name;
                var monchas = db.Mons.Where(m => m.LangID == a && m.ParentID == null&&m.SubjectID==s.ID).ToList();
                s.MonLS = new List<MonLS>();
                foreach (var mc in monchas)
                {
                    MonLS monls = new MonLS();
                    monls.ID = mc.ID;
                    monls.Name = mc.Name;
                    monls.Mons = db.Mons.Where(m => m.ParentID == mc.ID && m.LangID == a).ToList();
                    s.MonLS.Add(monls);
                }
                listls.Add(s);
            }
            
            return PartialView(listls);
        }
    }
}
